/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 *
 * @author Ricardo
 */
public abstract class AbstractConnection {
    
    private Connection conn;

    public Connection getConnection(String url, String user, String pass)
            throws SQLException {

        if (conn == null || conn.isClosed()) {
            Properties props = new Properties();
            props.put("user", user);
            props.put("password", pass);
            
            conn = DriverManager.getConnection(url, props);
        }

        return conn;
    }
    
    public void closeConnection() throws SQLException {
        if (conn != null)
            conn.close();
    }

    public abstract Connection getConnection() throws SQLException;
}
